package com.example.demo.pojo;

/**
 * <p>
 *
 * @Description: Result
 * </p>
 * @Author yangjiwang
 * @Date 2023/2/27
 */
public class Result<T> {
    /**
     * 成功值
     */
    private static final int SUCCESS_CODE = 200;
    /**
     * 失败值
     */
    private static final int ERROR_CODE = 0;

    /**
     * 返回代码
     */
    private int code;

    /**
     * 返回参数
     */
    private String message;

    /**
     * Data
     */
    private T data;

    private Result(int code){
        this.code = code;
    }

    private Result(int code, T data){
        this.code = code;
        this.data = data;
    }

    private Result(int code, String message){
        this.code = code;
        this.message = message;
    }

    private Result(int code, String message, T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode(){
        return code;
    }

    public String getMessage(){
        return message;
    }

    public T getData(){
        return data;
    }

    public static <T> Result<T> ok(){
        return new Result<T>(SUCCESS_CODE,"success");
    }
    public static <T> Result<T> ok(String message){
        return new Result<T>(SUCCESS_CODE,message);
    }
    public static <T> Result<T> ok(T data){
        return new Result<T>(SUCCESS_CODE,data);
    }
    public static <T> Result<T> ok(String message, T data){
        return new Result<T>(SUCCESS_CODE,message,data);
    }

    public static <T> Result<T> error(){
        return new Result<T>(ERROR_CODE,"error");
    }
    public static <T> Result<T> error(String message){
        return new Result<T>(ERROR_CODE,message);
    }
    public static <T> Result<T> error(int code, String message){
        return new Result<T>(code,message);
    }
}
